package com.cty.dubbo.service.impl;

import com.cty.dubbo.service.MenuDubboService;
import com.cty.mapper.MenuMapper;
import com.cty.pojo.Menu;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: cty
 * @Date: 2020/3/25 12:08
 * @Description: 服务实现类
 * @version: 1.0
 */

public class MenuDubboServiceImpl implements MenuDubboService {
    Logger log = Logger.getLogger(MenuDubboServiceImpl.class);

    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> selAllDubboService() {
        List<Menu> menus = this.menuMapper.selAll();
        for(Menu menu:menus){
            menu.setParent(this.menuMapper.selById(menu.getPid()));  // 设置父菜单
            menu.setChildren(this.menuMapper.selByPid(menu.getId()));
        }
        log.info("已从数据库查询所有菜单信息：\n"+menus);
        return menus;
    }

    @Override
    public Menu selOneDubboService(int id) {
        Menu menu = this.menuMapper.selById(id);
        menu.setParent(this.menuMapper.selById(menu.getPid()));
        menu.setChildren(this.menuMapper.selByPid(menu.getId()));

        return menu;
    }

    @Override
    public int updOneDubboService(Menu menu) {
        return this.menuMapper.updMenu(menu);
    }
}
